@extends('admin.default')
@section('title', '添加管理员')
@section('content')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label">
                        <span class="x-red">*</span>登录名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="username" name="username" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>将会成为您唯一的登入名
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>姓名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>管理员姓名
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="mobile" class="layui-form-label">
                        <span class="x-red">*</span>手机
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="mobile" name="mobile" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>11位手机号码
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        <span class="x-red">*</span>邮箱
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="email" name="email"  class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="gender"  title="男" value="1" checked="">
                        <input type="radio" name="gender"  title="女" value="2">
                        <input type="radio" name="gender"  title="保密" value="3">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">
                        <span class="x-red">*</span>密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="password" name="password"   class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        6到16个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="password_confirmation" name="password_confirmation"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="x-red">*</span>状态</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="role_id" value="1">
                        <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" value="1" checked>
                    </div>
                </div>{{csrf_field()}}
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        增加
                    </button>
                </div>
            </form>
        </div>
    </div>
    <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                form.on('submit(add)',
                    function(data) {
                        console.log(data);
                        //发异步，把数据提交给php
                        data = data.field;
                        $.ajax({
                            type: 'POST',
                            url: '{{route('admin.manager.store')}}',
                            data: data,
                            dataType: 'json',
                            success: function (data){
                                if(data == 1){
                                    layer.alert('修改成功', {
                                        icon: 1,
                                        skin: 'layui-layer-molv' //样式类名
                                        ,closeBtn: 0
                                    }, function(){
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                        parent.location.reload();
                                    });
                                } else{
                                    layer.alert('修改失敗', {
                                        icon: 2,
                                        skin: 'layui-layer-molv' //样式类名
                                        ,closeBtn: 0
                                    });
                                }
                            },
                            error: function(res){
                                var msg=JSON.parse(res.responseText);
                                layer.alert(msg.message, {
                                    icon: 2,
                                    title: '提示信息',
                                    skin: 'layui-layer-molv' //样式类名
                                    ,closeBtn: 0
                                });
                            }
                        });
                        return false;
                    });

            });</script>
@stop
